﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace ApiGateWay
{
    public class Program
    {
        /// <summary>
        /// 是否使用Consul的Docker集群
        /// </summary>
        public static bool IsConsulDockerCluster => true;

        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostContext, config) =>
            {
                if(IsConsulDockerCluster)
                {
                    config.AddJsonFile("ocelot-docker.json", false, true);
                }
                else
                {
                    config.AddJsonFile("ocelot.json", false, true);
                }
            })
                .UseStartup<Startup>();
        //new WebHostBuilder()
        //    .UseKestrel((context, opt) => { opt.AddServerHeader = false; })
        //    .UseContentRoot(Directory.GetCurrentDirectory())
        //    .ConfigureAppConfiguration((hostingContext, config) =>
        //    {
        //        var env = hostingContext.HostingEnvironment;
        //        // 根据环境变量加载不同JSON配置
        //        config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
        //            .AddJsonFile("ocelot.json").AddEnvironmentVariables(); //从环境变量添加配置
        //    })
        //    .UseIISIntegration()
        //    .ConfigureLogging((hostingContext, logging) =>
        //    {
        //        logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
        //        // 添加 控制台日志,Docker环境下请务必启用
        //        logging.AddConsole();
        //        // 添加调试日志
        //        logging.AddDebug();
        //    })
        //    .UseStartup<Startup>();
    }
}
